<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 网站地址
String netPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<jsp:include page="/WEB-INF/views/layouts/header.jsp"/>
<style>
.yhgltable ul li span.current{font-weight:bold}
</style>
<script type="text/javascript">
	function toInsert(){
		document.location="<%=basePath%>account/createOperator"
	}
	/**
	把指定的一组checkbox所选的值构造为逗号分隔的字符串
	*/
	function getAllValue(group_box) {
		var boxes = document.getElementsByName(group_box);
		var values = "";
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				values += boxes[i].value + ",";
			}
		}
		if (values.length > 0) {
			values = values.substring(0, values.length - 1);
		}
		return values;
	}
	function deleteUser(){
		var operatorIds = getAllValue("group_box");
		if(!operatorIds){
			alert("请选择需要删除的用户！");
			return;
		}
		$.ajax({
		  url: "<%=basePath%>account/delOperators",
		  type:"POST",
		  contentType:"application/x-www-form-urlencoded; charset=utf-8",
		  data: "operatorIds="+operatorIds,
		  dataType: 'text',
		  success: function(data) {
			 var jsonobj=eval('('+data+')');
			 if(jsonobj.state==='1'){
				 alert(jsonobj.result);
				 var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
				 var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
				 var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
				 if(currentPage>=1){
					$(".userContent").load("<%=basePath%>account/operators?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
				 }
			 }else if(jsonobj.state==='0'){
				 alert(jsonobj.result);
			 }
		  },
		  error: function(XMLHttpRequest, textStatus, errorThrown) {
				 alert("删除失败！");
		  }
		});
	}
	function toUpdate(){
		var boxes = document.getElementsByName("group_box");
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				var operatorId = boxes[i].value;
				break;
			}
		}
		if(!operatorId) {
			alert("请选择需要修改的用户！");
			return ;
		}
		window.location="<%=basePath%>account/updateOperator?operatorId="+operatorId;
	}
	function search(obj){
		var searchText = encodeURIComponent($(obj).prev().val()?$(obj).prev().val():"");
		var selectDepartmentId = $("li.current").attr("data-id")?$("li.current").attr("data-id"):"";
		$(".userContent").load("<%=basePath%>account/operators?departmentId="+selectDepartmentId+"&searchText="+searchText+"&rd="+Math.random());
	}
	function prevPage(){
		var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
		var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
		var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
		if(currentPage>1){
			currentPage--;
			$(".userContent").load("<%=basePath%>account/operators?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
		}
	}
	function nextPage(){
		var searchText = encodeURIComponent($("[name=searchText]").val()?$("[name=searchText]").val():"");
		var currentPage = $("[name=currentPage]").val()?parseInt($("[name=currentPage]").val()):1;
		var departmentId = $("[name=departmentId]").val()?$("[name=departmentId]").val():"";
		var totalPage = parseInt($("[name=totalPage]").val());
		if(currentPage<totalPage){
			currentPage++;
			$(".userContent").load("<%=basePath%>account/operators?departmentId="+departmentId+"&searchText="+searchText+"&page="+currentPage+"&rd="+Math.random());
		}
	}
</script>

<!--中间部分开始-->
<div class="main">
  <!-- 左侧 -->
  <jsp:include page="/WEB-INF/views/account/sidebar.jsp"/>
  <!-- /左侧 -->
  <!-- 核心内容区域 -->
	<div id="iaas_layout_content" class="rightblock">
    	<p class="shadow"></p>
    	<div class="content"><!--默认状态下引用样式ml60，展开后引用样式ml140-->
	      	<div class="mainblock">
	        	<div class="tabA">
	          		<h1>用户管理</h1>
	        	</div>
	        	<div class="lineone mt10"> 
		        	<span><img src="<%=basePath%>images/back.png" class="prev linkhand" style="cursor:pointer;" onclick="prevPage()" /><img src="<%=basePath%>images/next.png" class="next linkhand" style="cursor:pointer;" onclick="nextPage()" /></span>
		          	<div class="btn"> <a href="javascript:void(0)" onclick="toInsert()"><img src="<%=basePath%>images/xz.gif" />新增</a> <a href="javascript:void(0)" onclick="deleteUser()"><img src="<%=basePath%>images/del.gif" />删除</a> <a href="javascript:void(0)" onclick="toUpdate()"><img src="<%=basePath%>images/xg.gif" />修改</a></div>
		          	<%-- <div class="search">
		            	<input type="text" name="searchText" />
		            	<img src="<%=basePath%>images/search.png" onclick="search(this)" class="linkhand"/> 
		            </div> --%>
		        </div>
		        
		        <table border="0" cellpadding="0" cellspacing="0" class="yhgltable mt10" style="width: 100%">
			          <tr>
			            <!-- <td width="15%" class="rycp">系统成员</td> -->
			            <td rowspan="2" class="userContent" valign="top"><script>$(".userContent").load("<%=basePath%>account/operators?rd="+Math.random())</script></td>
			          </tr>
			          <!-- <tr>
			            <td valign="top">
			            <ul class="dm-menu">
			                
			              </ul>
			              <script>
			              		var jsonArray = eval('${rootDepartmentList}');
			              		if(jsonArray){
			              			$(".dm-menu").html(buildTree(jsonArray));
			              		}
			              		function buildTree(jsonArray){
			              			var html = "";
			              			html = buildNode(jsonArray[0]);
			              			return html;
			              		}
			              		function buildNode(json){
			              			var nodeHtml="<li data-id="+json.departmentId+">";
			              			var name = json.name;
			              			var num = json.operatorCount;
			              			nodeHtml+="<span style=\"cursor:pointer;\">"+name+" ("+num+"人"+")</span>";
			              			for(var j=0;j<json.childDepartmentList.length;j++){
		              					nodeHtml+="<ul>";
		              					nodeHtml+=buildNode(json.childDepartmentList[j]);
		              					nodeHtml+="</ul>";
		              				}
			              			nodeHtml+"</li>"
			              			return nodeHtml;
			              		}
			              </script>
			              </td>
			          </tr> -->
        		</table>
		        
		        
	      	</div>  
    	</div>
  	</div>
</div>
<script type="text/javascript">
var root = $('.dm-menu');
var menuTree = $('.dm-menu li');
menuTree.each(function(i,el){
	var ul = $(this).children('ul');
	if(ul.size() > 0){
		$(this).addClass('haschild');
		ul.css('display','none');
	}
	var obj = this;
	$(this).click(function(event){
		event.stopPropagation();
		if(ul.size() > 0){
			if(event.target == this){
				ul.toggle();
				$(this).toggleClass('expand');
			}else{
				$(".current").removeClass("current");
				$(obj).children("span").addClass('current');
				var dataId = $(this).attr("data-id");
				if(dataId){
					$(".userContent").load("<%=basePath%>account/operators?departmentId="+dataId+"&rd="+Math.random());
				}else{
					$(".userContent").load("<%=basePath%>account/operators?rd="+Math.random());
				}
			}
		}else{
			$(".current").removeClass("current");
			$(this).addClass('current');
			var dataId = $(this).attr("data-id");
			if(dataId){
				$(".userContent").load("<%=basePath%>account/operators?departmentId="+dataId+"&rd="+Math.random());
			}else{
				$(".userContent").load("<%=basePath%>account/operators?rd="+Math.random());
			}
		}
	});
});
$('.dm-menu > li').addClass('expand').children('ul').show();
</script>
<!--中间部分结束-->
<!--底部开始-->
<jsp:include page="/WEB-INF/views/layouts/footer.jsp"/>
<!--底部结束-->

</body>
</html>
